/* GUI CONVERTED from rspsmtb.p (converter v1.76) Sun May 19 19:42:57 2002 */
/* rspsmtb.p - Supplier Planning Schedules Detail Maintenence            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                   */
/* All rights reserved worldwide.  This is an unpublished work.          */
/*V8:ConvertMode=Maintenance                                             */
/*V8:RunMode=Character,Windows                                           */
/* REVISION: 9.0     CREATED: 05/15/98           BY: *K1QZ* Suresh Nayak */
/* REVISION: 9.0    MODIFIED: 03/13/99           BY: *M0BD* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb              */
/* REVISION:$       LAST MODIFIED: 05/20/02   BY: *P070* Lena Lim         */

/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */

          /* DISPLAY TITLE */
          {mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* **************** Begin Translatable Strings Definitions **************** */

         &SCOPED-DEFINE rspsmtb_p_1 "Item"
         /* Max Len: Comment: This is the abbreviation for Item Number */

         &SCOPED-DEFINE rspsmtb_p_2 "Int"
         /* Max Len: Comment: This is the abbreviation for Interval    */

         &SCOPED-DEFINE rspsmtb_p_3 " Planning Schedule Detail Data "
         /* Max Len: Comment: This is the frame name for detail maintenance */

/* ***************** End Translatable Strings Definitions ***************** */

          define input parameter sch_recid as recid no-undo.
          define output parameter schd_recid as recid no-undo.
          define variable i as integer no-undo.
          define variable schddet_recid as recid no-undo.
          define variable where_we_are as integer no-undo.
          define variable del-yn like mfc_logical no-undo.
          define variable cmmts like mfc_logical label {&rspsmtb_p_1} no-undo.
          define variable prior_cum_qty like schd_upd_qty no-undo.
          define new shared variable cmtindx like cmt_indx.
          define variable new_schd_det like mfc_logical no-undo.

          define variable l_ref_time as character format "99:99" no-undo.
          define variable l_dummy_length as character format "999:99" no-undo.
          define variable l_msgnbr as integer no-undo.
          define variable l_schd_time like schd_time no-undo.
          define variable l_date as date no-undo.
          define variable l_old_schd_upd_qty like schd_upd_qty no-undo.
          define variable l_new_schd_upd_qty like schd_upd_qty no-undo.
          define variable l_old_schd_fc_qual like schd_fc_qual no-undo.
          define variable l_new_schd_fc_qual like schd_fc_qual no-undo.
          define variable l_schd_ref like schd_reference no-undo.
          define variable l_schd_interval like schd_interval no-undo.

          for first sch_mstr where recid(sch_mstr) = sch_recid
          no-lock: end.

          for first pod_det where pod_nbr = sch_nbr and pod_line = sch_line
          no-lock: end.

          for each schd_det where schd_type = sch_type
          and schd_nbr = sch_nbr
          and schd_line = sch_line
          and schd_rlse_id = sch_rlse_id
          exclusive-lock:

             if sch_cumulative then do:
                schd_upd_qty = schd_cum_qty.
             end. /* END OF IF sch_cumulative */

             else do:
                schd_upd_qty = schd_discr_qty.
             end. /* END OF LESE DO */
          end.  /* FOR EACH schd_det */

          FORM /*GUI*/ 
             space (5)
             schd_date
             schd_time
             schd_interval label {&rspsmtb_p_2}
             schd_reference
             schd_upd_qty
             schd_fc_qual
          with frame sched_det down centered
          /*V8+*/ attr-space width 80
          no-validate title color normal
          (getFrameTitle("PLANNING_SCHEDULE_DETAIL_DATA",41)) THREE-D /*GUI*/.


          /* SET EXTERNAL LABELS */
          setFrameLabels(frame sched_det:handle).

          pause 0.
          mainloop:

          do transaction with frame sched_det:

             clear frame sched_det all no-pause.
             view frame sched_det.
             for first schd_det where schd_type = sch_type
             and schd_nbr = sch_nbr and schd_line = sch_line
             and schd_rlse_id = sch_rlse_id
             no-lock: end.
             i = 0.

             do while i < frame-down and available schd_det:
                 display
                     schd_date
                     schd_time
                     schd_interval
                     schd_reference
                     schd_upd_qty
                     schd_fc_qual
                 with frame sched_det.
                 i = i + 1.

                 if i < frame-down then down 1.
                 find next schd_det where schd_type = sch_type
                 and schd_nbr = sch_nbr
                 and schd_line = sch_line
                 and schd_rlse_id = sch_rlse_id
                 no-lock no-error.
             end. /* END OF DO WHILE i < FRAME-DOWN AND AVAILABLE schd_det */

             up frame-line - 1.
             for first schd_det where schd_type = sch_type
             and schd_nbr = sch_nbr and schd_line = sch_line
             and schd_rlse_id = sch_rlse_id
             no-lock: end.

             detail-loop:
             repeat with frame sched_det:
/*GUI*/ if global-beam-me-up then undo, leave.


                ststatus = stline[1].
                status input ststatus.
                pause before-hide.
                prompt-for schd_date schd_time schd_interval schd_reference
                go-on(F9 F10 CURSOR-UP CURSOR-DOWN).
                pause 0.

                if frame-field = "schd_date" then
                next-prompt schd_date.
                else
                if frame-field = "schd_time" then
                next-prompt schd_time.
                else
                if frame-field = "schd_interval" then
                next-prompt schd_interval.
                else
                if frame-field = "schd_reference" then
                next-prompt schd_reference.

                if input schd_date = ? then do:
                    {mfmsg.i 27 3}
                    next-prompt schd_date with frame sched_det.
                    undo , retry.
                end. /* END OF IF schd_date = ? */

                if lookup(input schd_interval,"D,M,W") = 0 then
                do:
                    /* VALID VALUES ARE D, W OR M */
                    {mfmsg.i 4368 3}
                    next-prompt schd_interval with frame sched_det.
                    undo , retry.
                end. /* END OF IF LOOKUP(input schd_time) */

                assign
                    l_ref_time = substring(string(time,"HH:MM"),1,2)
                               + substring(string(time,"HH:MM"),4,2)
                    l_msgnbr = 0
                    l_schd_time = input schd_time.

                /* FSTIMCHK WILL RETURN ONE OF TWO POTENTIAL  */
                /* ERRORS.  #30 IS FOR MINUTES > 59.  #69     */
                /* INDICATES NON-NUMERIC INPUT, IN WHICH CASE */
                /* WE WANT TO PRESERVE AND REDISPLAY THE USER */
                /* INPUT.                                     */

                {gprun.i ""fstimchk.p""
                         "(input  ""T"",
                           input l_schd_time,
                           input  """",
                           output l_ref_time,
                           output l_dummy_length,
                           output l_msgnbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                if l_msgnbr <> 0 then do:
                    {mfmsg.i l_msgnbr 3}
                    next-prompt schd_time with frame sched_det.
                    undo, retry.
                end. /* END OF IF l_msgnbr <> 0 */

                do while
                lastkey = keycode("F9")
                or lastkey = keycode("CURSOR-UP")
                or lastkey = keycode("F10")
                or lastkey = keycode("CURSOR-DOWN")
                on endkey undo , leave detail-loop:

                   if available schd_det then do:

                      if lastkey = keycode("F9")
                      or lastkey = keycode("CURSOR-UP")
                      then do:
                         find prev schd_det where schd_type = sch_type
                         and schd_nbr = sch_nbr
                         and schd_line = sch_line
                         and schd_rlse_id = sch_rlse_id
                         exclusive-lock no-error.

                         if available schd_det then do:
                            up 1.
                            display
                            schd_date
                            schd_time
                            schd_interval
                            schd_reference
                            schd_upd_qty
                            schd_fc_qual.
                         end. /* END OF IF AVAILABLE schd_det */

                         else do:
                            for first schd_det where schd_type = sch_type
                            and schd_nbr = sch_nbr
                            and schd_line = sch_line
                            and schd_rlse_id = sch_rlse_id
                            exclusive-lock: end.
                            bell.
                         end.  /* END OF ELSE DO */

                      end. /* END OF IF LASTKEY = KEYCODE(F9) */

                      else
                      if lastkey = keycode("F10")
                      or lastkey = keycode("CURSOR-DOWN")
                      then do:
                         find next schd_det where schd_type = sch_type
                         and schd_nbr = sch_nbr
                         and schd_line = sch_line
                         and schd_rlse_id = sch_rlse_id
                         exclusive-lock no-error.

                         if available schd_det then do:
                            down 1.
                            display
                            schd_date
                            schd_time
                            schd_interval
                            schd_reference
                            schd_upd_qty
                            schd_fc_qual.
                         end. /* END OF IF AVAILABLE schd_det */

                         else do:
                            find last schd_det where schd_type = sch_type
                            and schd_nbr = sch_nbr
                            and schd_line = sch_line
                            and schd_rlse_id = sch_rlse_id
                            exclusive-lock no-error.
                            bell.
                         end. /* END OF ELSE DO */

                      end. /* END OF IF LASTKEY = KEYCODE(F10) */

                   end.  /* END OF IF AVAILABLE schd_det */

                   ststatus = stline[1].
                   status input ststatus.
                   pause before-hide.
                   prompt-for schd_date schd_time schd_interval schd_reference
                   go-on(F9 F10 CURSOR-UP CURSOR-DOWN).
                   pause 0.

                   if frame-field = "schd_date" then
                   next-prompt schd_date.
                   else
                   if frame-field = "schd_time" then
                   next-prompt schd_time.
                   else
                   if frame-field = "schd_interval" then
                   next-prompt schd_interval.
                   else
                   if frame-field = "schd_reference" then
                   next-prompt schd_reference.

                   if input schd_date = ? then do:
                      {mfmsg.i 27 3}
                      next-prompt schd_date with frame sched_det.
                      undo , retry.
                   end. /* END OF IF input schd_date = ? */

                   if lookup(input schd_interval,"D,M,W") = 0 then
                   do:
                       /* VALID VALUES ARE D,W OR M */
                       {mfmsg.i 4368 3}
                       next-prompt schd_interval with frame sched_det.
                       undo , retry.
                   end. /* END OF IF LOOKUP(input schd_time)  */

                   assign
                       l_ref_time = substring(string(time,"HH:MM"),1,2)
                                  + substring(string(time,"HH:MM"),4,2)
                       l_msgnbr = 0
                       l_schd_time = input schd_time.

                   /* FSTIMCHK WILL RETURN ONE OF TWO POTENTIAL  */
                   /* ERRORS.  #30 IS FOR MINUTES > 59.  #69     */
                   /* INDICATES NON-NUMERIC INPUT, IN WHICH CASE */
                   /* WE WANT TO PRESERVE AND REDISPLAY THE USER */
                   /* INPUT.                                     */

                   {gprun.i ""fstimchk.p""
                            "(input  ""T"",
                              input  l_schd_time,
                              input  """",
                              output l_ref_time,
                              output l_dummy_length,
                              output l_msgnbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                   if l_msgnbr <> 0 then do:
                       {mfmsg.i l_msgnbr 3}
                       next-prompt schd_time with frame sched_det.
                       undo, retry.
                   end. /* END OF IF l_msgnbr <> 0 */

                end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* END OF DO WHILE LASTKEY = KEYCODE("F9") */

                for first schd_det where schd_type = sch_type
                and schd_nbr = sch_nbr
                and schd_line = sch_line
                and schd_rlse_id = sch_rlse_id
                and schd_date = input schd_date
                and schd_time = input schd_time
                and schd_interval = input schd_interval
                and schd_reference = input schd_reference
                exclusive-lock: end.

                if not available schd_det then do:
                    new_schd_det = yes.
                    {mfmsg.i 1 1}
                    create schd_det.
                    assign
                        schd_type = sch_type
                        schd_nbr = sch_nbr
                        schd_line = sch_line
                        schd_rlse_id = sch_rlse_id
                        schd_date
                        schd_time
                        schd_interval
                        schd_reference.

                        if recid(schd_det) = -1 then .

                        schd_recid = recid(schd_det).

                end. /* END OF IF NOT AVAILABLE schd_det */

                else new_schd_det = no.
                schddet_recid = recid(schd_det).
                where_we_are = frame-line.

                do i = 1 to where_we_are while available schd_det:
                    find prev schd_det where schd_type = sch_type
                    and schd_nbr = sch_nbr
                    and schd_line = sch_line
                    and schd_rlse_id = sch_rlse_id
                    no-lock no-error.
                end. /* END OF DO = i TO where_we_are */

                up where_we_are - 1.

                do i = 1 to frame-down:
                    find next schd_det where schd_type = sch_type
                    and schd_nbr = sch_nbr
                    and schd_line = sch_line
                    and schd_rlse_id = sch_rlse_id
                    no-lock no-error.

                    if available schd_det then do:
                        display
                            schd_date
                            schd_time
                            schd_interval
                            schd_reference
                            schd_upd_qty
                            schd_fc_qual.

                        if recid(schd_det) = schddet_recid then do:
                           where_we_are = frame-line.
                        end.

                    end. /* END OF IF AVAILABLE schd_det */

                    else do:
                       display
                       "" @ schd_date
                       "" @ schd_time
                       "" @ schd_interval
                       "" @ schd_reference
                       "" @ schd_upd_qty
                       "" @ schd_fc_qual.
                    end. /* END OF ELSE DO */

                   if i < frame-down then down 1.
                end. /* END OF DO i = 1 TO FRAME-DOWN */

                up frame-down - where_we_are.
                for first schd_det where recid(schd_det) = schddet_recid
                exclusive-lock: end.
                schddet_recid = recid(schd_det).
                ststatus = stline[2].
                status input ststatus.

                do on error undo , retry:
/*GUI*/ if global-beam-me-up then undo, leave.

                   pause before-hide.
                   display
                       schd_date
                       schd_time
                       schd_interval
                       schd_reference
                       schd_upd_qty
                       schd_fc_qual.

                   l_old_schd_upd_qty = schd_upd_qty.
                   l_old_schd_fc_qual = schd_fc_qual.

                   l_new_schd_upd_qty = input schd_upd_qty.

                   prompt-for schd_upd_qty schd_fc_qual

                   /*V8+*/
                         go-on(ESC F5 CTRL-D F9 F10 CURSOR-UP CURSOR-DOWN).   

                   if input schd_fc_qual = "f" and pod_firm_days = 0 then do:
                      {mfmsg.i 8198 3} /* FIRM NOT ALLWD, FIRM DAYS IS 0 */
                      next-prompt schd_fc_qual.
                      undo, retry.
                   end.
                   pause 0.
                end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* END OF DO ON ERROR UNDO , RETRY */

                if keyfunction(lastkey) = "END-ERROR" then
                do:
                  undo detail-loop, retry detail-loop.
                end.

                if frame-field = "schd_upd_qty" then
                next-prompt schd_upd_qty.
                else
                if frame-field = "schd_fc_qual" then
                next-prompt schd_fc_qual.

                do while lastkey = keycode("F9")
                or lastkey = keycode("CURSOR-UP")
                or lastkey = keycode("F10")
                or lastkey = keycode("CURSOR-DOWN"):
                   new_schd_det = no.

                   if lastkey = keycode("F9")
                   or lastkey = keycode("CURSOR-UP")
                   then do:
                      assign
                      l_old_schd_upd_qty = schd_upd_qty
                      schd_upd_qty
                      l_new_schd_upd_qty = input schd_upd_qty
                      l_old_schd_fc_qual = schd_fc_qual
                      schd_fc_qual
                      l_new_schd_fc_qual = input schd_fc_qual
                      l_date = input schd_date
                      l_schd_ref = input schd_reference
                      l_schd_interval = input schd_interval
                      l_schd_time = input schd_time
                      .

                     /* ROUTINE TO UPDATE SCHEDULE TYPE 4 WHEN THE
                        PLANNING SCHEDULE HAS BEEN CHANGED */

                      if sch_rlse_id = pod_curr_rlse_id[2] then do:

                         run sched_update (input recid(sch_mstr),
                                           input pod_curr_rlse_id[1],
                                           input l_date,
                                           input l_old_schd_upd_qty,
                                           input l_new_schd_upd_qty,
                                           input l_old_schd_fc_qual,
                                           input l_new_schd_fc_qual,
                                           input l_schd_time,
                                           input l_schd_interval,
                                           input l_schd_ref
                                          ).
                      end.

                      find prev schd_det where schd_type = sch_type
                      and schd_nbr = sch_nbr
                      and schd_line = sch_line
                      and schd_rlse_id = sch_rlse_id
                      exclusive-lock no-error.

                      if available schd_det then do:
                         up 1.
                         display
                         schd_date
                         schd_time
                         schd_interval
                         schd_reference
                         schd_upd_qty
                         schd_fc_qual.
                      end. /* END OF IF AVAILABLE schd_det */

                      else do:
                         for first schd_det where schd_type = sch_type
                         and schd_nbr = sch_nbr
                         and schd_line = sch_line
                         and schd_rlse_id = sch_rlse_id
                         exclusive-lock: end.
                         bell.
                      end.  /* END OF ELSE DO */

                   end. /* END OF IF LASTKEY = KEYCODE(F9)  */

                   else
                   if lastkey = keycode("F10")
                   or lastkey = keycode("CURSOR-DOWN")
                   then do:
                      assign
                      l_old_schd_upd_qty = schd_upd_qty
                      schd_upd_qty
                      l_new_schd_upd_qty = input schd_upd_qty
                      l_old_schd_fc_qual = schd_fc_qual
                      schd_fc_qual
                      l_new_schd_fc_qual = input schd_fc_qual
                      l_date = input schd_date
                      l_schd_time = input schd_time
                      l_schd_interval = input schd_interval
                      l_schd_ref = input schd_reference
                      .

                      /* ROUTINE TO UPDATE SCHEDULE TYPE 4 WHEN THE
                         PLANNING SCHEDULE HAS CHANGED */

                      if sch_rlse_id = pod_curr_rlse_id[2] then do:

                         run sched_update (input recid(sch_mstr),
                                           input pod_curr_rlse_id[1],
                                           input l_date,
                                           input l_old_schd_upd_qty,
                                           input l_new_schd_upd_qty,
                                           input l_old_schd_fc_qual,
                                           input l_new_schd_fc_qual,
                                           input l_schd_time,
                                           input l_schd_interval,
                                           input l_schd_ref
                                          ).
                      end.

                      find next schd_det where schd_type = sch_type
                      and schd_nbr = sch_nbr
                      and schd_line = sch_line
                      and schd_rlse_id = sch_rlse_id
                      exclusive-lock no-error.

                      if available schd_det then do:
                         down 1.
                         display
                         schd_date
                         schd_time
                         schd_interval
                         schd_reference
                         schd_upd_qty
                         schd_fc_qual.
                      end. /* END OF IF AVAILABLE schd_det */

                      else do:
                         find last schd_det where schd_type = sch_type
                         and schd_nbr = sch_nbr
                         and schd_line = sch_line
                         and schd_rlse_id = sch_rlse_id
                         exclusive-lock no-error.
                         bell.
                      end.  /* END OF ELSE DO */

                   end.  /* END OF IF LASTKEY = KEYCODE(F10)  */

                   ststatus = stline[2].
                   status input ststatus.

                   do on error undo , retry:
/*GUI*/ if global-beam-me-up then undo, leave.

                      pause before-hide.
                      prompt-for schd_upd_qty schd_fc_qual

                      /*V8+*/
                            go-on(ESC F5 CTRL-D F9 F10 CURSOR-UP
                            CURSOR-DOWN).   

                      if input schd_fc_qual = "f" and pod_firm_days = 0 then do:
                         {mfmsg.i 8198 3} /* FIRM NOT ALLWD, FIRM DAYS IS 0 */
                         next-prompt schd_fc_qual.
                         undo, retry.
                      end.
                      pause 0.
                   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* END OF DO ON ERROR UNDO , RETRY */

                   if frame-field = "schd_upd_qty" then
                   next-prompt schd_upd_qty.
                   else
                   if frame-field = "schd_fc_qual" then
                   next-prompt schd_fc_qual.
                end. /* END OF DO WHILE LASTKEY = KEYCODE("F9") */

                do while lastkey = keycode("F9")
                or lastkey = keycode("CURSOR-UP")
                or lastkey = keycode("F10")
                or lastkey = keycode("CURSOR-DOWN"):
                   new_schd_det = no.

                   if frame-field = "schd_upd_qty" then
                   next-prompt schd_upd_qty.
                   else
                   if frame-field = "schd_fc_qual" then
                   next-prompt schd_fc_qual.
                end. /* END OF DO WHILE LASTKEY = KEYCODE("F9") */

                if lastkey = keycode("F5")
                or lastkey = keycode("CTRL-D") then do:
                   del-yn = yes.
                   {mfmsg01.i 11 1 del-yn}

                   if del-yn = no then do:
                      display
                      schd_date
                      schd_time
                      schd_interval
                      schd_reference
                      schd_upd_qty
                      schd_fc_qual.
                      next detail-loop.
                   end. /* END OF IF del-yn */

                   for first schd_det where schd_type = sch_type
                   and schd_nbr = sch_nbr and schd_line = sch_line
                   and schd_rlse_id = sch_rlse_id
                   and schd_date = input schd_date
                   and schd_time = input schd_time
                   and schd_interval = input schd_interval
                   and schd_reference = input schd_reference
                   exclusive-lock: end.

                   assign
                      l_old_schd_upd_qty = schd_upd_qty
                      l_new_schd_upd_qty = 0
                      l_old_schd_fc_qual = schd_fc_qual
                      l_new_schd_fc_qual = "P"
                      l_date = input schd_date
                      l_schd_time = input schd_time
                      l_schd_interval = input schd_interval
                      l_schd_ref = input schd_reference
                      .

                   delete schd_det.

                   /* ROUTINE TO UPDATE SCHEDULE TYPE 4 WHEN THE
                      PLANNING SCHEDULE HAS CHANGED */

                   if sch_rlse_id = pod_curr_rlse_id[2] then do:

                      run sched_update (input recid(sch_mstr),
                                        input pod_curr_rlse_id[1],
                                        input l_date,
                                        input l_old_schd_upd_qty,
                                        input l_new_schd_upd_qty,
                                        input l_old_schd_fc_qual,
                                        input l_new_schd_fc_qual,
                                        input l_schd_time,
                                        input l_schd_interval,
                                        input l_schd_ref
                                       ).
                   end.

                   where_we_are = frame-line.
                   find next schd_det where schd_type = sch_type
                   and schd_nbr = sch_nbr
                   and schd_line = sch_line
                   and schd_rlse_id = sch_rlse_id
                   no-lock no-error.

                   if available schd_det then do:
                      schddet_recid = recid(schd_det).
                      display
                      schd_date
                      schd_time
                      schd_interval
                      schd_reference
                      schd_upd_qty
                      schd_fc_qual.

                      do i = where_we_are to frame-down - 1:
                         down 1.
                         find next schd_det where schd_type = sch_type
                         and schd_nbr = sch_nbr
                         and schd_line = sch_line
                         and schd_rlse_id = sch_rlse_id
                         no-lock no-error.

                         if available schd_det then do:
                            display
                            schd_date
                            schd_time
                            schd_interval
                            schd_reference
                            schd_upd_qty
                            schd_fc_qual.
                         end. /* END OF IF AVAILABLE schd_det */

                         else do:
                            display
                            "" @ schd_date
                            "" @ schd_time
                            "" @ schd_interval
                            "" @ schd_reference
                            "" @ schd_upd_qty
                            "" @ schd_fc_qual.
                         end. /* END OF ELSE DO */

                      end. /* END OF DO i = where_we_are TO FRAME-DOWN - 1 */

                      up frame-down - where_we_are.
                      for first schd_det where recid(schd_det) = schddet_recid
                      exclusive-lock: end.
                   end. /* END OF IF AVAILABLE schd_det */

                   else do:
                      display
                      "" @ schd_date
                      "" @ schd_time
                      "" @ schd_interval
                      "" @ schd_reference
                      "" @ schd_upd_qty
                      "" @ schd_fc_qual.

                      find prev schd_det where schd_type = sch_type
                      and schd_nbr = sch_nbr
                      and schd_line = sch_line
                      and schd_rlse_id = sch_rlse_id
                      exclusive-lock no-error.

                      if available schd_det then do:
                         up 1.
                         display
                         schd_date
                         schd_time
                         schd_interval
                         schd_reference
                         schd_upd_qty
                         schd_fc_qual.
                      end. /* END OF IF AVAILABLE schd_det */

                   end. /* END OF ELSE DO OF IF AVAILABLE schd_det */

                end. /* END OF IF LASTKEY = KEYCODE("F5") */
                else
                if keyfunction(lastkey) = "END-ERROR"
                then do:
                   display
                   schd_upd_qty
                   schd_fc_qual.
                end. /* END OF IF KEYFUNCTION(LASTKEY) = "END-ERROR" */

                else do:
                   assign
                   l_old_schd_upd_qty = schd_upd_qty
                   schd_upd_qty
                   l_new_schd_upd_qty = input schd_upd_qty
                   l_old_schd_fc_qual = schd_fc_qual
                   schd_fc_qual
                   l_new_schd_fc_qual = input schd_fc_qual
                   l_date = input schd_date
                   l_schd_time = input schd_time
                   l_schd_interval = schd_interval
                   l_schd_ref = schd_reference
                   .

                   /* ROUTINE TO UPDATE SCHEDULE TYPE 4 WHEN THE
                      PLANNING SCHEDULE HAS CHANGED */

                   if sch_rlse_id = pod_curr_rlse_id[2] then do:

                      run sched_update (input recid(sch_mstr),
                                        input pod_curr_rlse_id[1],
                                        input l_date,
                                        input l_old_schd_upd_qty,
                                        input l_new_schd_upd_qty,
                                        input l_old_schd_fc_qual,
                                        input l_new_schd_fc_qual,
                                        input l_schd_time,
                                        input l_schd_interval,
                                        input l_schd_ref
                                       ).
                   end.

                   if new_schd_det and frame-line <> frame-down then do:
                      schddet_recid = recid(schd_det).
                      where_we_are = frame-line.

                      do i = 1 to where_we_are + 1 while available schd_det:
                         find prev schd_det where schd_type = sch_type
                         and schd_nbr = sch_nbr
                         and schd_line = sch_line
                         and schd_rlse_id = sch_rlse_id
                         no-lock no-error.
                      end. /* END OF DO i = 1 to where_we_are + 1 */

                      up where_we_are - 1.

                      do i = 1 to frame-down:
                         find next schd_det where schd_type = sch_type
                         and schd_nbr = sch_nbr
                         and schd_line = sch_line
                         and schd_rlse_id = sch_rlse_id
                         no-lock no-error.

                         if available schd_det then do:
                            display
                            schd_date
                            schd_time
                            schd_interval
                            schd_reference
                            schd_upd_qty
                            schd_fc_qual.

                            if recid(schd_det) = schddet_recid then do:
                               where_we_are = frame-line.
                            end.

                         end. /* END OF IF AVAILABLE schd_det */

                         else do:
                            display
                            "" @ schd_date
                            "" @ schd_time
                            "" @ schd_interval
                            "" @ schd_reference
                            "" @ schd_upd_qty
                            "" @ schd_fc_qual.
                         end. /* END OF ELSE DO */

                         if i < frame-down then down 1.
                      end. /* END OF DO i = 1 TO FRAME-DOWN */

                      up frame-down - where_we_are.
                      for first schd_det where recid(schd_det) = schddet_recid
                      exclusive-lock: end.
                      schddet_recid = recid(schd_det).
                   end. /* END OF IF new_schd_det & FRAME-LINE <> FRAME-DOWN */

                end. /* END OF ELSE DO */

             end. /* END OF REPEAT WITH FRAME sched_det: Detail loop */

             prior_cum_qty = sch_pcr_qty.
             for each schd_det where schd_type = sch_type
             and schd_nbr = sch_nbr
             and schd_line = sch_line
             and schd_rlse_id = sch_rlse_id
             exclusive-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


                if sch_cumulative then do:

                   if schd_upd_qty < prior_cum_qty then do:
                      {mfmsg.i 6009 3} /* CUM QTYS NOT IN ASCENDING ORDER */
                      undo mainloop , retry mainloop.
                   end. /* END OF IF schd_upd_qty < prioir_cum_qty */

                   schd_cum_qty = schd_upd_qty.
                   schd_discr_qty = schd_cum_qty - prior_cum_qty.
                   prior_cum_qty = prior_cum_qty + schd_discr_qty.
                end. /* END OF IF sch_cumulative */

                else do:
                   schd_discr_qty = schd_upd_qty.
                   prior_cum_qty = prior_cum_qty + schd_discr_qty.
                   schd_cum_qty = prior_cum_qty.
                end. /* END OF ELSE DO */

             end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* END OF FOR EACH schd_det */

          end. /* END OF DO TRANSACTION WITH FRAME sched_det */

          ststatus = stline[2].
          status input ststatus.
          hide frame sched_det no-pause.
          pause before-hide.

          PROCEDURE sched_update:

              define input parameter sch_recid as recid no-undo.
              define input parameter l_pod_curr_rlse_id
                                           like pod_curr_rlse_id[1] no-undo.
              define input parameter l_date as date no-undo.
              define input parameter l_old_schd_upd_qty
                                           like schd_upd_qty    no-undo.
              define input parameter l_new_schd_upd_qty
                                           like schd_upd_qty    no-undo.
              define input parameter l_old_schd_fc_qual
                                           like schd_fc_qual    no-undo.
              define input parameter l_new_schd_fc_qual
                                           like schd_fc_qual    no-undo.
              define input parameter l_schd_time like schd_time no-undo.
              define input parameter l_schd_interval like schd_interval no-undo.
              define input parameter l_schd_ref like schd_reference no-undo.
              define buffer b_sch_mstr for sch_mstr.
              define buffer b_schd_det for schd_det.

              for first b_sch_mstr where recid(b_sch_mstr) = sch_recid
              no-lock: end.

              for first b_schd_det where schd_type = 4 and
                  schd_nbr = b_sch_mstr.sch_nbr        and
                  schd_line = b_sch_mstr.sch_line      and
                  schd_rlse_id = l_pod_curr_rlse_id    and
                  schd_date = l_date exclusive-lock: end.

                  if available b_schd_det then
                  do:

                      if sch_cumulative then
                      do:
                          if schd_cum_qty - l_old_schd_upd_qty
                              + l_new_schd_upd_qty > 0
                          then
                              schd_cum_qty =
                                 schd_cum_qty - l_old_schd_upd_qty
                                     + l_new_schd_upd_qty.
                          else
                              schd_cum_qty = 0.
                      end.
                      else do:
                          if schd_discr_qty - l_old_schd_upd_qty +
                              l_new_schd_upd_qty > 0
                          then
                              schd_discr_qty =
                                 schd_discr_qty - l_old_schd_upd_qty
                                    + l_new_schd_upd_qty.
                          else
                              schd_discr_qty = 0.
                      end.
                      if l_old_schd_fc_qual <> l_new_schd_fc_qual then do:
                         assign
                           schd_fc_qual = l_new_schd_fc_qual.
                      end.
                  end. /* end of if available schd_det */

                  if not available b_schd_det then do:
                     create schd_det.
                        assign
                           schd_det.schd_type = 4
                           schd_det.schd_nbr = b_sch_mstr.sch_nbr
                           schd_det.schd_line = b_sch_mstr.sch_line
                           schd_det.schd_rlse_id = l_pod_curr_rlse_id
                           schd_det.schd_date = l_date
                           schd_det.schd_time = l_schd_time
                           schd_det.schd_interval = l_schd_interval
                           schd_det.schd_reference = l_schd_ref
                           schd_det.schd_discr_qty = l_new_schd_upd_qty
                           schd_det.schd_fc_qual = l_new_schd_fc_qual
                           .

                      if recid(schd_det) = -1 then .
                   end.

          END PROCEDURE. /* END PROCEDURE sched_update */
